package bairui.international.console.web.controller.advance.category.product;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.querydsl.core.BooleanBuilder;

import bairui.international.console.web.controller.advance.category.C_Advance_Category_Detail_ProductPage;
import bairui.international.model.domain.jpa.QTB_Product;
import bairui.international.model.domain.jpa.TB_Product;
import bairui.international.service.Service_Product;
import bairui.international.service.Service_ProductPropertyItem;

/**
 *
 * 产品导出
 *
 * @generated
 * 
 * @see STest_C_Advance_Category_ProductExport_ExcelExport 测试
 *
 */
@Controller
public class C_Advance_Category_ProductExport_ExcelExport
 extends SC_Advance_Category_ProductExport_ExcelExport 
{
	
	private final QTB_Product QProduct = QTB_Product.tB_Product;
	@Autowired private Service_Product service_Product;
	@Autowired private Service_ProductPropertyItem service_ProductPropertyItem;
	
	/**
	 * 导出Excel文件
	 */
	@Action(ExcelExport.class)
	@PostMapping(ExcelExport.RequestMappingValue)
	public void excelExport(
		HttpServletRequest request,
		HttpServletResponse response,
		@Valid ExcelExport.Input input, 
		@PathVariable(name=ExcelExport.PathVariableName.CategoryId) long categoryId
	) throws Exception {
		BooleanBuilder query = C_Advance_Category_Detail_ProductPage.filter(QProduct, categoryId, request);
		List<Long> ids = input.getId();
		if(!ids.isEmpty()){
			query.and(QProduct.id.in(ids));
		}
		//
		java.util.List<TB_Product> list = service_Product.list(
						it->query, 
						it->C_Advance_Category_Detail_ProductPage.sort(it,request)
					).getContent();
		// 处理属性
		list.forEach(it->C_Advance_Category_Detail_ProductPage.gainProperty(it, service_ProductPropertyItem));
		//
		ExcelExport.Output.output(
				list,
				request, 
				response
			);
	}
	

}
